class Mutations::CreateUser < GraphQL::Function
  argument :id, types.ID
  argument :name, types.String
  argument :email, types.String
  argument :phone_number, types.Int
  argument :is_admin, types.Boolean
  argument :country_id, types.Int

  type Types::UserType # especificação do tipo de retorno

  def call(obj, args, context)
    begin
      user = User.new(args.to_h)
      user.save!
      user
    rescue ActiveRecord::RecordInvalid
      GraphQL::ExecutionError.new("#{user.errors.full_messages.join(', ')}")
    end
  end
end
